import numpy as np, scipy.special as sp, scipy.integrate as ig, copy, re, math
import sys
from Model import Model,Actor,Evidence,TrackSegment,Node,TimeNode,Time,Distributions

class Walk:

    def __init__(self):
        self.model = Model()
        self.model.name = "Walk"
        self.model.subscriptions = [""]
        self.model.topNode = "walkmain"
        self.model.independent = True

        act1 = Actor()
        act1.name = "dummy1"
        act1.atype = Actor.NULL

        tempNode = Node()
        tempNode.getID()
        tempNode.name = "walkmain"
        tempNode.subjects = [act1]
        tempNode.objects = []
        tempNode.evvecs = []
        tempNode.bound = False

        self.model.topNode = tempNode.name
        self.model.nodes.append(copy.deepcopy(tempNode))

        tempNode.name = "walksub"
        tempEv = TrackSegment()
        tempEv.actor = act1
        tempEv.segtype = Evidence.MOVE
        tempEv.willBind = True
        tempEv.endsNode = True
        tempEv.bound = False

        tempNode.evvecs = [copy.deepcopy(tempEv)]

        def walkJoint(evvecs):
            track = evvecs[0]
            speed = track.calculate_speed()
            print "calculated speed:",speed
            speedWeight = Walk.speedDensity(speed)
            print "weight:",speedWeight
            return speedWeight,.5

        tempNode.lfunction = walkJoint

        self.model.nodes.append(copy.deepcopy(tempNode))

    @staticmethod
    def speedDensity(speed):
        """saying average walking speed is ~1.4 m/s"""
#        weight = Distributions.PDFs.gamma(speed,26,1/.57)
        weight = Distributions.PDFs.gamma(speed,3.0,1/.5) 
        return weight
